//
//  ZLNavigationController.swift
//  Swift-weibo
//
//  Created by 朱万龙 on 2016/12/9.
//  Copyright © 2016年 zwl. All rights reserved.
//

import UIKit

class ZLNavigationController: UINavigationController {

    override func loadView() {
        super.loadView()
        //隐藏系统navBar
        navigationBar.isHidden = true
    }
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {

        //如果不是栈底的控制器才需要隐藏tabBar
        if childViewControllers.count > 0 {
            //隐藏TabBar
            viewController.hidesBottomBarWhenPushed = true
            
            //判断控制器类型
            if let vc = viewController as? ZLBaseViewController {
                
                var title = "返回"
                //判断控制器级数
                if childViewControllers.count == 1 {
                    //取出栈中第一个控制器title 设置返回按钮
                    title = childViewControllers.first?.title ?? "返回"
                }
                //添加leftItem  设置返回按钮
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, fontSize: 16, target: self, action: #selector(leftItemCilk), isBack: true)
            }
            
        }
        super.pushViewController(viewController, animated: true)
    }
    func leftItemCilk(){
        popViewController(animated: true)
    }
    
}
